const request = require('request')
const jar = request.jar()

const loginHandle = require('./login')
const urlHandle = require('./url')
const saveHandle = require('./save')

const findPatientById = (_id, patients) => {
  for (let k = 0; k < patients.length; k += 1) {
    if (patients[k]._id === _id) {
      return patients[k]
    }
  }
  return null
}
module.exports.loginHandle = (username, password, cb) => {
  loginHandle(username, password, jar, cb)
}
module.exports.urlHandle = (url, cb) => {
  urlHandle(url, jar, cb)
}
module.exports.saveHandle = (arg, patients, cb) => {
  saveHandle(arg, findPatientById(arg._id, patients), jar, cb)
}
